package cn.yangliu.nacos.comm.model;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

import static cn.yangliu.nacos.comm.constant.GlobalValidateConstants.PAGE_NUMBER_ILLEGAL;
import static cn.yangliu.nacos.comm.constant.GlobalValidateConstants.PAGE_NUMBER_MISS;
import static cn.yangliu.nacos.comm.constant.GlobalValidateConstants.PAGE_SIZE_ILLEGAL;
import static cn.yangliu.nacos.comm.constant.GlobalValidateConstants.PAGE_SIZE_MISS;

import lombok.Data;
import org.hibernate.validator.constraints.Range;
import org.springframework.data.domain.PageRequest;

/**
 * The type of nacos.
 *
 * @author 问道于盲
 * @date 2020 -01-01
 */
@Data
public class PageModel {

    /**
     * current class instance's member.
     * The Page.
     */
    @Min(value = 0, message = PAGE_NUMBER_ILLEGAL)
    @NotNull(message = PAGE_NUMBER_MISS)
    private Integer page;

    /**
     * current class instance's member.
     * The Size.
     */
    @Range(min = 1, max = 1000, message = PAGE_SIZE_ILLEGAL)
    @NotNull(message = PAGE_SIZE_MISS)
    private Integer size;

    /**
     * Build page request.
     *
     * @return the page request
     */
    public PageRequest build() {
        return PageRequest.of(page, size);
    }
}
